using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fated.SaveEngine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;

namespace Fated {
    /*
    class MainMenu : Renderable{
        private enum StartupState { PressStart, Login, LoggingIn, Storage, StorageOpen, MainMenu, LoadScreen, Finished };
        private string[] menuItems = new string[] { "New Game", "Load Game", "Exit"};
        private int menushift = 0;
        private int currentIndex = 0;

        Renderable textout;
        Renderable selectBox;

        private long stick;

        private StartupState state = StartupState.PressStart;
        private StorageDevice storage = null;
        private StorageContainer container = null;

        private PlayerIndex firstPlayer = PlayerIndex.One;

        //Initializes press start screen
        public MainMenu() : base() {
            stick = TimingMngr.registerControl();
            this.renderType = RenderType.None;
            textout = new Renderable();
            this.children.Add(textout);
            textout.renderType = RenderType.Text;
            textout.text = "Press Start";
        }

        //Initializes the Main Menu;
        private void displayMenu() {
            textout.text = "Main Menu";

            int cnt = 0;
            menushift = this.children.Count();
            currentIndex = this.children.Count();

            Vector2 textSize = Vector2.Zero;
            int widest = 0;
            foreach (string item in menuItems) {
                Renderable temp = new Renderable();
                temp.renderType = RenderType.Text;
                temp.text = item;

                textSize = RenderMngr.textSize(item, temp.fontID);
                float x = (screenSize.X  - textSize.X) / 2;
                float y = screenSize.Y * 2 / 3 + textSize.Y * cnt++;

                if (widest < textSize.X) widest = (int)textSize.X;

                temp.textPos = new Vector2(x, y);
                this.children.Add(temp);
            }
            widest += 4;
            selectBox = new Renderable();
            selectBox.renderType = RenderType.NonIsoBitmap;
            selectBox.tint = Color.FromNonPremultiplied(0, 0, 255, 128);
            selectBox.textureID = 1;
            selectBox.textureSize = new Rectangle((int)(screenSize.X - widest) / 2, (int)this.children[menushift].textPos.Y, widest, (int)textSize.Y);
            this.children.Add(selectBox);
        }

        public void update(double timeElapsed) {
            if (state == StartupState.LoadScreen) {
                updateLoadScreen(timeElapsed);
                return;
            }
            //If we haven't figured out which pad the player is playing from.
            if (state == StartupState.PressStart) {
                for (PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++) {
                    if (GamePad.GetState(i).Buttons.Start == ButtonState.Pressed) {
                        firstPlayer = i;
                        state = StartupState.Login;
                        break;
                    }
                }
            }
            //If that controller isn't signed in.
            if (state == StartupState.Login) {
                displayMenu();
                if (Gamer.SignedInGamers[firstPlayer] == null) {
                    Guide.ShowSignIn(1, false);
                    state = StartupState.LoggingIn;
                } else if (Gamer.SignedInGamers[firstPlayer] != null) {
                    state = StartupState.Storage;
                }
            }
            //If we're signing that person in.
            if (state == StartupState.LoggingIn && Gamer.SignedInGamers[firstPlayer] != null) {
                    state = StartupState.Storage;
            }
            //If they have more than one memory unit
            if (state == StartupState.Storage) {
                if (Guide.IsVisible) return;
                StorageDevice.BeginShowSelector(firstPlayer, finishedStorage, null);
                state = StartupState.StorageOpen;
            }
            //Now we're ready to play.
            if (state == StartupState.MainMenu) {
                GamePadState padState = GamePad.GetState(firstPlayer);
                if (TimingMngr.tickAvailable(padState.ThumbSticks.Left, TimingMngr.Controls.LeftStick, timeElapsed)) {

                    currentIndex = currentIndex + (padState.ThumbSticks.Left.Y > 0 ? -1 : 1);

                    if (currentIndex < menushift) currentIndex = menushift + menuItems.Length - 1;
                    if (currentIndex >= menushift + menuItems.Length) currentIndex = menushift;
                    selectBox.textureSize.Y = (int)this.children[currentIndex].textPos.Y;
                }
                if (padState.Buttons.A == ButtonState.Pressed) {
                    state = StartupState.Finished;
                }
            }
        }
        private void finishedStorage(IAsyncResult result) {
            storage = StorageDevice.EndShowSelector(result); //Get storage device
            if (storage == null) {
                state = StartupState.Storage;
                return;
            }
            IAsyncResult r = storage.BeginOpenContainer("Fated Game Data", null, null);
            r.AsyncWaitHandle.WaitOne(); //Wait to finish opening container
            container = storage.EndOpenContainer(r);

            SaveEngine.initialize(container);

            state = StartupState.MainMenu;
        }

        private void updateLoadScreen(double timeElapsed){

        }
        public void loadScreen() {
            this.children.Clear();
            //this.children.Add(new LoadScreen());
        }
    #region Getters/Setters
        public PlayerIndex getCurrentPlayerIndex() {
            return firstPlayer;
        }
        public bool isFinished() {
            return state == StartupState.Finished;
        }
        public StorageContainer getStorageContainer() {
            return container;
        }
        public int getSelected() {
            return currentIndex - menushift;
        }
    #endregion
    }*/
}
